package cn.com.generaldata.os.service.indicator_evaluation.national_economy_contribution;

import org.apache.commons.lang3.Validate;
import org.nutz.dao.sql.Criteria;

import cn.com.generaldata.jsme_indicator_system.entity.IndicatorEvaluation;
import cn.com.generaldata.os.service.indicator_constant.ProvinceIndicatorConstant;
import cn.com.generaldata.os.service.indicator_evaluation.IndicatorEvaluationCalculateService;
import cn.com.generaldata.os.vo.IndicatorAccountVO;

/**
 * 海洋经济对国民经济的拉动评估指标计算类.
 */
public class MEPullNECalculateService extends IndicatorEvaluationCalculateService {

	private String MECIndicatorName = ProvinceIndicatorConstant.MEC_INDICATOR_NAME;
	private String GDPIndicatorName = ProvinceIndicatorConstant.GDP_INDICATOR_NAME;

	@Override
	protected Double calculate(IndicatorEvaluation indicator, IndicatorAccountVO indicatorAccountVO) {

		Double calculate = getMECIndicatorVal(indicatorAccountVO);
		Double GDP = getGDP(indicatorAccountVO, indicatorAccountVO.getYear());
		Double lastGDP = getGDP(indicatorAccountVO, indicatorAccountVO.getYear() - 1);

		return (GDP - lastGDP) / lastGDP * calculate * 100;
	}

	private Double getMECIndicatorVal(IndicatorAccountVO indicatorAccountVO)
	{
		Integer MEClIndicatorId = getIndicatorEvaluationId(MECIndicatorName, indicatorAccountVO.getAreaId());

		Criteria cri = getIndicatorDataCri(indicatorAccountVO, indicatorAccountVO.getYear(), MEClIndicatorId);
		Double result = getEvaluationIndicatorValue(cri);
		Validate.isTrue(result != null);
		return result;
	}

	private Double getGDP(IndicatorAccountVO indicatorAccountVO, int year) {

		Double result = getInputOrAccountingIndicatorValue(indicatorAccountVO, year,
				GDPIndicatorName);
		Validate.isTrue(result != null);
		return result;
	}

}
